/*
    This file is part of Manhunt.

    Manhunt is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Manhunt is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Manhunt.  If not, see <https://www.gnu.org/licenses/>.
 */

package snw.manhunt.tasks;

import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import snw.manhunt.managers.ConfigManager;
import snw.manhunt.managers.GameManager;

import static snw.manhunt.managers.GameManager.getHunters;

public class HunterWaitTimeOut extends BukkitRunnable {
    private int time = ConfigManager.getHunterWaitTime();

    @Override
    public void run() {
        for (String o : getHunters()) {
            Player i = Bukkit.getPlayerExact(o);
            if (i == null) {
                getHunters().remove(o);
                continue;
            }
            if (time >= 4 && time <= 10) {
                i.sendTitle(ChatColor.GREEN + "" + time + "...", "", 0, 70, 0);
            } else if (time <= 3 && time >= 1) {
                i.sendTitle(ChatColor.RED + "" + time + "...", "", 0, 70, 0);
            } else {
                i.sendTitle(ChatColor.DARK_RED + "" + "GO!!!", "", 0, 70, 0);
                i.playSound(i.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.MASTER, 10, 0);
                i.getInventory().addItem(new ItemStack(Material.COMPASS, 1));
                GameManager.setHunterSetOut(true);
                cancel();
            }
            time--;
        }
    }
}